package com.edgelight.service.impl;


import com.edgelight.dao.TbUserRepository;
import com.edgelight.dao.UserMapper;
import com.edgelight.pojo.Tbuser;
import com.edgelight.service.UserService;
import com.edgelight.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service
public class UserServiceimpl implements UserService {
    @Autowired
    TbUserRepository tbUserRepository;
    @Autowired
    UserMapper userMapper;

    @Override
    public ResultMsg login(String account, String password, HttpSession session) {
        Tbuser byUserName = tbUserRepository.findByUsername(account);
        session.setAttribute("user",byUserName);
        ResultMsg resultMsg = new ResultMsg();
        if (byUserName!=null&&(byUserName.getUserpass())==password){
            resultMsg.setCode(100);
        }else {
            resultMsg.setCode(101);
        }
        System.out.println(byUserName);
        return resultMsg;
    }

    @Override
    public ResultMsg zhuce(Tbuser tbuser) {
        ResultMsg resultMsg = new ResultMsg();
        int insert = userMapper.insert(tbuser);
        if (insert==1){
            resultMsg.setCode(100);
        }else {
            resultMsg.setCode(101);
        }
        return resultMsg;
    }
}
